package com.czy.owner.ui.hotshop;

import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.czy.owner.R;
import com.czy.owner.adapter.GoodsListAdapter;
import com.czy.owner.api.BrandH5ListApi;
import com.czy.owner.api.BrandListApi;
import com.czy.owner.api.BrandStoreH5ListApi;
import com.czy.owner.api.HotShopGoodsListApi;
import com.czy.owner.api.HotShopStoreListApi;
import com.czy.owner.api.HotShopSupplierListApi;
import com.czy.owner.api.StoreBrandListApi;
import com.czy.owner.api.StoreGoodsListApi;
import com.czy.owner.callback.RecycleViewDivider;
import com.czy.owner.db.UserHelper;
import com.czy.owner.entity.BrandListModel;
import com.czy.owner.entity.GoodsListModel;
import com.czy.owner.global.Constants;
import com.czy.owner.net.api.BaseResultEntity;
import com.czy.owner.net.http.HttpManager;
import com.czy.owner.net.listener.HttpOnNextListener;
import com.czy.owner.ui.BaseActivity;
import com.czy.owner.utils.MyLog;
import com.czy.owner.utils.PhoneUtils;
import com.czy.owner.utils.SharedPreferencesUtils;
import com.czy.owner.utils.StringUtils;
import com.czy.owner.widget.TagsLayout;
import com.easyrecycleview.EasyRecyclerView;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by asus
 * 商品列表
 */
public class GoodsListActivity extends BaseActivity implements RecyclerArrayAdapter.OnLoadMoreListener, SwipeRefreshLayout.OnRefreshListener {

    @BindView(R.id.tv_order_by_sales)
    TextView tvOrderBySales;
    @BindView(R.id.tv_order_by_price)
    TextView tvOrderByPrice;
    @BindView(R.id.iv_order_by_price)
    ImageView ivOrderByPrice;
    @BindView(R.id.ll_order_by_price)
    LinearLayout llOrderByPrice;
    @BindView(R.id.tv_screen_condition)
    TextView tvScreenCondition;
    @BindView(R.id.iv_screen_condition)
    ImageView ivScreenCondition;
    @BindView(R.id.ll_screen_condition)
    LinearLayout llScreenCondition;
    @BindView(R.id.rv_goods_list)
    EasyRecyclerView rvGoodsList;
    @BindView(R.id.tv_page_title_center)
    TextView tvPageTitleCenter;
    private boolean priceDesc = false;
    private boolean isFirst = true;


    private GoodsListAdapter goodsListAdapter;
    private PopupWindow popWnd;
    private List<TextView> screenTextViews = new ArrayList<>();
    private int page = 1;
    private Handler handler = new Handler();
    private static final int CLASSIFY_TYPE = 0;
    private String queryField = "salesDown";
    private int goodsBrandId = 0;
    private List<BrandListModel.BrandListBean> goodsBrandList = new ArrayList<>();
    private static final int PLATFORM_TYPE = 0;
    private static final int SUPPLIER_TYPE = 2;
    private static final int STORE_TYPE = 3;
    private int goodsType;
    private String goodsActivityId;
    private String  mFromType ;
    private String  mFromTypeId ;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_goods_list;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initViews() {
        //yqj 17/09/22 标题优化
        if (TextUtils.isEmpty(getIntent().getStringExtra("title"))) {
            tvPageTitleCenter.setText(R.string.goods_list);
        } else {
            tvPageTitleCenter.setText(getIntent().getStringExtra("title"));
        }

        goodsType = getIntent().getIntExtra("goodsType", PLATFORM_TYPE);
        goodsActivityId = getIntent().getStringExtra("goodsActivityId");
        goodsBrandId = getIntent().getIntExtra("goodsBrandId", 0);
        mFromType = getIntent().getStringExtra("mFromType");
        mFromTypeId = getIntent().getStringExtra("mFromTypeId");
        tvOrderBySales.setEnabled(true);
        tvOrderByPrice.setEnabled(false);
        tvScreenCondition.setEnabled(false);
        ivScreenCondition.setEnabled(false);
        ivOrderByPrice.setEnabled(priceDesc);
        ivOrderByPrice.setImageResource(R.drawable.selector_arrow_normal);
        initGoods();
    }

    private void initGoods() {
        goodsListAdapter = new GoodsListAdapter(this);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        rvGoodsList.setAdapterWithProgress(goodsListAdapter);
        rvGoodsList.setLayoutManager(linearLayoutManager);
        rvGoodsList.addItemDecoration(new RecycleViewDivider(this, LinearLayoutManager.VERTICAL, R.drawable.shape_recyclerview_divider_decoration));
        goodsListAdapter.setMore(R.layout.view_more, this);
        goodsListAdapter.setNoMore(R.layout.view_nomore, new RecyclerArrayAdapter.OnNoMoreListener() {
            @Override
            public void onNoMoreShow() {
                //adapter.resumeMore();
            }

            @Override
            public void onNoMoreClick() {
                goodsListAdapter.resumeMore();
            }
        });

        goodsListAdapter.setError(R.layout.view_error_net, new RecyclerArrayAdapter.OnErrorListener() {
            @Override
            public void onErrorShow() {
                goodsListAdapter.resumeMore();

            }

            @Override
            public void onErrorClick() {
                goodsListAdapter.resumeMore();

            }
        });

        goodsListAdapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position, Object o) {
                Intent intent = new Intent(GoodsListActivity.this, GoodsDetailActivity.class);
                GoodsListModel.GoodsPageBean.ListBean listBean = (GoodsListModel.GoodsPageBean.ListBean) o;
                intent.putExtra("goodsId", listBean.getGoodsId());
                intent.putExtra("mFromType",mFromType);
                intent.putExtra("mFromTypeId",mFromTypeId);
                MyLog.e("yang","GoodList__mFromTypeId=="+mFromTypeId);
                startActivity(intent);
            }

        });

        rvGoodsList.setRefreshListener(this);
        onRefresh();

    }

    private void getBrandData(final View view) {
        if (goodsType == PLATFORM_TYPE) {
            BrandListApi brandListApi = new BrandListApi(new HttpOnNextListener<BrandListModel>() {
                @Override
                public void onNext(BrandListModel model) {
                    List<BrandListModel.BrandListBean> list = model.getBrandList();
                    initPop(list);
                    showScreenPop(view);
                }

                @Override
                public void onError(Throwable e) {
                    super.onError(e);
                    MyLog.e("asus", e.toString());
                    PhoneUtils.ShowToastMessage(GoodsListActivity.this, e.getMessage());
                }
            }, this);
            brandListApi.setSession(UserHelper.getInstance().getSession(GoodsListActivity.this));
            brandListApi.setStoreId(SharedPreferencesUtils.getParam(GoodsListActivity.this, UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0) + "");
            if (getIntent().getIntExtra("fromType", CLASSIFY_TYPE) == CLASSIFY_TYPE) {
                brandListApi.setCategoryId(getIntent().getIntExtra("categoryId", 0) + "");
            } else {
                brandListApi.setGoodsName(getIntent().getStringExtra("searchStr"));
            }
            brandListApi.setGoodsActivityId(goodsActivityId);
            HttpManager manager = HttpManager.getInstance();
            manager.doHttpDeal(brandListApi);
        } else if (goodsType == SUPPLIER_TYPE) {
            BrandH5ListApi brandH5ListApi = new BrandH5ListApi(new HttpOnNextListener<List<BrandListModel.BrandListBean>>() {
                @Override
                public void onNext(List<BrandListModel.BrandListBean> listBeans) {
//                    List<BrandListModel.BrandListBean> list = model.getBrandList();
                    initPop(listBeans);
                    showScreenPop(view);
                }

                @Override
                public void onError(Throwable e) {
                    super.onError(e);
                    MyLog.e("asus", e.toString());
                    PhoneUtils.ShowToastMessage(GoodsListActivity.this, e.getMessage());
                }
            }, this);
            brandH5ListApi.setSession(UserHelper.getInstance().getSession(GoodsListActivity.this));
            brandH5ListApi.setSupplierId(getIntent().getStringExtra("supplierId"));

            brandH5ListApi.setGoodsActivityId(goodsActivityId);
            HttpManager manager = HttpManager.getInstance();
            manager.doHttpDeal(brandH5ListApi);
        } else if (goodsType == STORE_TYPE) {
            BrandStoreH5ListApi brandStoreH5ListApi = new BrandStoreH5ListApi(new HttpOnNextListener<List<BrandListModel.BrandListBean>>() {
                @Override
                public void onNext(List<BrandListModel.BrandListBean> listBeans) {
//                    List<BrandListModel.BrandListBean> list = model.getBrandList();
                    initPop(listBeans);
                    showScreenPop(view);
                }

                @Override
                public void onError(Throwable e) {
                    super.onError(e);
                    MyLog.e("asus", e.toString());
                    PhoneUtils.ShowToastMessage(GoodsListActivity.this, e.getMessage());
                }
            }, this);
            brandStoreH5ListApi.setSession(UserHelper.getInstance().getSession(GoodsListActivity.this));
            if (StringUtils.isEmpty(getIntent().getStringExtra("storeId"))) {
                brandStoreH5ListApi.setStoreId(SharedPreferencesUtils.getParam(GoodsListActivity.this, UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0) + "");
            } else {
                brandStoreH5ListApi.setStoreId(getIntent().getStringExtra("storeId"));
            }

            brandStoreH5ListApi.setGoodsActivityId(goodsActivityId);
            HttpManager manager = HttpManager.getInstance();
            manager.doHttpDeal(brandStoreH5ListApi);
        } else {
            StoreBrandListApi storeBrandListApi = new StoreBrandListApi(new HttpOnNextListener<BrandListModel>() {
                @Override
                public void onNext(BrandListModel model) {
                    List<BrandListModel.BrandListBean> list = model.getBrandList();
                    initPop(list);
                    showScreenPop(view);
                }

                @Override
                public void onCacheNext(String cache) {
                    super.onCacheNext(cache);
                    Gson gson = new Gson();
                    Type type = new TypeToken<BaseResultEntity<BrandListModel>>() {
                    }.getType();
                    BaseResultEntity<BrandListModel> cacheModel = gson.fromJson(cache, type);
                    initPop(cacheModel.getData().getBrandList());
                }

                @Override
                public void onError(Throwable e) {
                    super.onError(e);
                    MyLog.e("asus", e.toString());
                    PhoneUtils.ShowToastMessage(GoodsListActivity.this, e.getMessage());
                }
            }, this);
            storeBrandListApi.setSession(UserHelper.getInstance().getSession(GoodsListActivity.this));
            storeBrandListApi.setStoreId(SharedPreferencesUtils.getParam(GoodsListActivity.this, UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0) + "");
            if (getIntent().getIntExtra("fromType", CLASSIFY_TYPE) == CLASSIFY_TYPE) {
                storeBrandListApi.setCategoryId(getIntent().getIntExtra("categoryId", 0) + "");
            } else {
                storeBrandListApi.setGoodsName(getIntent().getStringExtra("searchStr"));
            }
            HttpManager manager = HttpManager.getInstance();
            manager.doHttpDeal(storeBrandListApi);

        }


    }

    private void initPop(List<BrandListModel.BrandListBean> brandList) {
        goodsBrandList.clear();
        goodsBrandList.addAll(brandList);

    }

    @Override
    protected void updateViews() {

    }

    @OnClick({R.id.ll_order_by_sales, R.id.ll_order_by_price, R.id.ll_screen_condition, R.id.btn_page_title_left})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_order_by_sales:
                isFirst = true;
                queryField = "salesDown";
                tvOrderBySales.setEnabled(true);
                tvOrderByPrice.setEnabled(false);
                tvScreenCondition.setEnabled(false);
                ivScreenCondition.setEnabled(false);
                ivOrderByPrice.setEnabled(priceDesc);
                ivOrderByPrice.setImageResource(R.drawable.selector_arrow_normal);
                goodsListAdapter.clear();
                page = 1;
                getDataList();
                break;
            case R.id.ll_order_by_price:
                tvOrderBySales.setEnabled(false);
                tvOrderByPrice.setEnabled(true);
                tvScreenCondition.setEnabled(false);
                ivScreenCondition.setEnabled(false);
                if (!isFirst) {
                    priceDesc = !priceDesc;
                }
                if (priceDesc) {
                    queryField = "priceDown";
                } else {
                    queryField = "priceUp";
                }
                isFirst = false;
                ivOrderByPrice.setEnabled(priceDesc);
                ivOrderByPrice.setImageResource(R.drawable.selector_arrow_selected);
                goodsListAdapter.clear();
                page = 1;
                getDataList();
                break;
            case R.id.ll_screen_condition:
                tvScreenCondition.setEnabled(true);
                ivScreenCondition.setEnabled(true);
                if (popWnd != null) {
                    popWnd.showAsDropDown(view);
                    //     popWnd.showAtLocation(view, Gravity.TOP, 0, 0);
                    setAlpha();
                } else {
                    getBrandData(view);
                }


                break;
            case R.id.btn_page_title_left:
                finish();
                break;
        }
    }

    private void showScreenPop(View view) {
        screenTextViews.clear();
        View contentView = LayoutInflater.from(GoodsListActivity.this).inflate(R.layout.pop_screen, null);
        popWnd = new PopupWindow(contentView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        ColorDrawable cd = new ColorDrawable(0x77000000);
        popWnd.setBackgroundDrawable(cd);
        popWnd.setBackgroundDrawable(new BitmapDrawable());
        popWnd.setOutsideTouchable(true);
        popWnd.setFocusable(true);
        TagsLayout tagsGoodsScreen = (TagsLayout) contentView.findViewById(R.id.tags_goods_screen);

        ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        for (int i = 0; i < goodsBrandList.size(); i++) {
            View v = View.inflate(GoodsListActivity.this, R.layout.item_screen_brand, null);
            TextView textView = (TextView) v.findViewById(R.id.tv_screen_item);
            if (goodsBrandId != 0 && goodsBrandList.get(i).getGoodsBrandId() == goodsBrandId) {
                textView.setTextColor(getResources().getColor(R.color.appThemeColor));
                textView.setBackgroundResource(R.drawable.shape_app_theme_frame);
            }
            textView.setText(goodsBrandList.get(i).getChName());
            textView.setTag(goodsBrandList.get(i).getGoodsBrandId());
            v.setTag(false);
            screenTextViews.add(textView);
            v.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    TextView tv = (TextView) v.findViewById(R.id.tv_screen_item);
                    updateTextView(tv);
                    popWnd.dismiss();
                    closepopuwindow();
                    onRefresh();
                }
            });
            tagsGoodsScreen.addView(v, lp);
        }
        contentView.findViewById(R.id.view_outside).setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (popWnd != null && popWnd.isShowing()) {
                    popWnd.dismiss();
                    closepopuwindow();
                }
                return false;
            }
        });

        popWnd.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                tvScreenCondition.setEnabled(false);
                ivScreenCondition.setEnabled(false);
                closepopuwindow();
            }
        });
        popWnd.showAsDropDown(view);
        // popWnd.showAtLocation(view, Gravity.TOP, 0, 0);
        setAlpha();
    }

    public void closepopuwindow() {
        WindowManager.LayoutParams lp = this.getWindow().getAttributes();
        lp.alpha = 1f;
        this.getWindow().setAttributes(lp);
    }

    public void setAlpha() {
        final WindowManager.LayoutParams params = this.getWindow().getAttributes();
        params.alpha = 0.5f;
        this.getWindow().setAttributes(params);
    }

    private void updateTextView(TextView tv) {

        int tag = (int) tv.getTag();
        MyLog.e("asus", tag + "---->" + goodsBrandId);
        if (goodsBrandId != 0) {
            if (goodsBrandId == tag) {
                goodsBrandId = 0;
            } else {
                goodsBrandId = tag;
            }
        } else {
            goodsBrandId = tag;
        }

        for (int i = 0; i < goodsBrandList.size(); i++) {
            if (goodsBrandId == goodsBrandList.get(i).getGoodsBrandId()) {
                screenTextViews.get(i).setTextColor(getResources().getColor(R.color.appThemeColor));
                screenTextViews.get(i).setBackgroundResource(R.drawable.shape_app_theme_frame);
            } else {
                screenTextViews.get(i).setTextColor(getResources().getColor(R.color.appThemeSubTitleColor));
                screenTextViews.get(i).setBackgroundResource(R.drawable.shape_gray_frame);
            }

        }

    }

    private void setDataList(List<GoodsListModel.GoodsPageBean.ListBean> list) {
        if (page == 1 && list.size() == 0) {
            rvGoodsList.setEmptyView(R.layout.view_empty_common);
            rvGoodsList.showEmpty();
        }
        if (list.size() < 9) {
            goodsListAdapter.stopMore();
        }
        if (list.size() == 0 && !PhoneUtils.isNetworkConnected(GoodsListActivity.this)) {
            goodsListAdapter.pauseMore();
            rvGoodsList.showError();
            return;
        }
        goodsListAdapter.addAll(list);
    }

    private void getDataList() {
        if (goodsType == PLATFORM_TYPE) {
            HotShopGoodsListApi hotShopGoodsListApi = new HotShopGoodsListApi(new HttpOnNextListener<GoodsListModel>() {
                @Override
                public void onNext(GoodsListModel model) {
                    List<GoodsListModel.GoodsPageBean.ListBean> list = model.getGoodsPage().getList();
                    setDataList(list);
                }

                @Override
                public void onCacheNext(String cache) {
                    super.onCacheNext(cache);
                    Gson gson = new Gson();
                    Type type = new TypeToken<BaseResultEntity<GoodsListModel>>() {
                    }.getType();
                    BaseResultEntity<GoodsListModel> cacheModel = gson.fromJson(cache, type);
                    setDataList(cacheModel.getData().getGoodsPage().getList());
                }

                @Override
                public void onError(Throwable e) {
                    super.onError(e);
                    MyLog.e("asus", e.toString());
                    PhoneUtils.ShowToastMessage(GoodsListActivity.this, e.getMessage());
                }
            }, this, page + "");
            hotShopGoodsListApi.setSession(UserHelper.getInstance().getSession(GoodsListActivity.this));
            hotShopGoodsListApi.setStoreId(SharedPreferencesUtils.getParam(GoodsListActivity.this, UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0) + "");
            hotShopGoodsListApi.setGoodsActivityId(goodsActivityId);
            hotShopGoodsListApi.setPage(page + "");
            hotShopGoodsListApi.setSize("10");
            if (getIntent().getIntExtra("fromType", CLASSIFY_TYPE) == CLASSIFY_TYPE) {
                hotShopGoodsListApi.setCategoryId(getIntent().getIntExtra("categoryId", 0) + "");
            } else {
                hotShopGoodsListApi.setGoodsName(getIntent().getStringExtra("searchStr"));
            }
            if (goodsBrandId != 0) {
                hotShopGoodsListApi.setGoodsBrandId(goodsBrandId + "");
            }
            hotShopGoodsListApi.setQueryField(queryField);
            hotShopGoodsListApi.setGoodsActivityId(goodsActivityId);
            HttpManager manager = HttpManager.getInstance();
            manager.doHttpDeal(hotShopGoodsListApi);
        } else if (goodsType == SUPPLIER_TYPE) {
            HotShopSupplierListApi hotShopSupplierListApi = new HotShopSupplierListApi(new HttpOnNextListener<GoodsListModel.GoodsPageBean>() {
                @Override
                public void onNext(GoodsListModel.GoodsPageBean model) {
                    List<GoodsListModel.GoodsPageBean.ListBean> list = model.getList();
                    setDataList(list);
                }

                @Override
                public void onCacheNext(String cache) {
                    super.onCacheNext(cache);
                    Gson gson = new Gson();
                    Type type = new TypeToken<BaseResultEntity<GoodsListModel>>() {
                    }.getType();
                    BaseResultEntity<GoodsListModel> cacheModel = gson.fromJson(cache, type);
                    setDataList(cacheModel.getData().getGoodsPage().getList());
                }

                @Override
                public void onError(Throwable e) {
                    super.onError(e);
                    MyLog.e("asus", e.toString());
                    PhoneUtils.ShowToastMessage(GoodsListActivity.this, e.getMessage());
                }
            }, this, page + "");
            hotShopSupplierListApi.setSession(UserHelper.getInstance().getSession(GoodsListActivity.this));
//            hotShopSupplierListApi.setStoreId(SharedPreferencesUtils.getParam(GoodsListActivity.this, UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0) + "");
            hotShopSupplierListApi.setGoodsActivityId(goodsActivityId);
            hotShopSupplierListApi.setPage(page + "");
            hotShopSupplierListApi.setSize("10");
            hotShopSupplierListApi.setSupplierId(getIntent().getStringExtra("supplierId"));
            if (StringUtils.isEmpty(getIntent().getStringExtra("storeId"))) {
                hotShopSupplierListApi.setStoreId(SharedPreferencesUtils.getParam(GoodsListActivity.this, UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0) + "");
            } else {
                hotShopSupplierListApi.setStoreId(getIntent().getStringExtra("storeId"));
            }
            if (goodsBrandId != 0) {
                hotShopSupplierListApi.setGoodsBrandId(goodsBrandId + "");
            }
            hotShopSupplierListApi.setQueryField(queryField);
            hotShopSupplierListApi.setGoodsActivityId(goodsActivityId);
            HttpManager manager = HttpManager.getInstance();
            manager.doHttpDeal(hotShopSupplierListApi);
        } else if (goodsType == STORE_TYPE) {
            HotShopStoreListApi hotShopStoreListApi = new HotShopStoreListApi(new HttpOnNextListener<GoodsListModel.GoodsPageBean>() {
                @Override
                public void onNext(GoodsListModel.GoodsPageBean model) {
                    List<GoodsListModel.GoodsPageBean.ListBean> list = model.getList();
                    setDataList(list);
                }

                @Override
                public void onCacheNext(String cache) {
                    super.onCacheNext(cache);
                    Gson gson = new Gson();
                    Type type = new TypeToken<BaseResultEntity<GoodsListModel>>() {
                    }.getType();
                    BaseResultEntity<GoodsListModel> cacheModel = gson.fromJson(cache, type);
                    setDataList(cacheModel.getData().getGoodsPage().getList());
                }

                @Override
                public void onError(Throwable e) {
                    super.onError(e);
                    MyLog.e("yang", e.toString());
                    PhoneUtils.ShowToastMessage(GoodsListActivity.this, e.getMessage());
                }
            }, this, page + "");
            hotShopStoreListApi.setSession(UserHelper.getInstance().getSession(GoodsListActivity.this));

            hotShopStoreListApi.setPage(page + "");
            hotShopStoreListApi.setSize("10");
            if (StringUtils.isEmpty(getIntent().getStringExtra("storeId"))) {
                hotShopStoreListApi.setStoreId(SharedPreferencesUtils.getParam(GoodsListActivity.this, UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0) + "");
            } else {
                hotShopStoreListApi.setStoreId(getIntent().getStringExtra("storeId"));
            }
            if (goodsBrandId != 0) {
                hotShopStoreListApi.setGoodsBrandId(goodsBrandId + "");
            }
            hotShopStoreListApi.setGoodsActivityId(goodsActivityId);
            hotShopStoreListApi.setQueryField(queryField);
            HttpManager manager = HttpManager.getInstance();
            manager.doHttpDeal(hotShopStoreListApi);
        } else {
            StoreGoodsListApi storeGoodsListApi = new StoreGoodsListApi(new HttpOnNextListener<GoodsListModel>() {
                @Override
                public void onNext(GoodsListModel model) {
                    List<GoodsListModel.GoodsPageBean.ListBean> list = model.getGoodsPage().getList();
                    setDataList(list);
                }

                @Override
                public void onError(Throwable e) {
                    super.onError(e);
                    MyLog.e("asus", e.toString());
                    PhoneUtils.ShowToastMessage(GoodsListActivity.this, e.getMessage());
                }
            }, this, page + "");
            storeGoodsListApi.setSession(UserHelper.getInstance().getSession(GoodsListActivity.this));
            storeGoodsListApi.setStoreId(SharedPreferencesUtils.getParam(GoodsListActivity.this, UserHelper.getInstance().getUserAccount() + Constants.SHARED_PREFERENCES_KEY_BINDSTOREID, 0) + "");
            storeGoodsListApi.setPage(page + "");
            storeGoodsListApi.setSize("10");
            if (getIntent().getIntExtra("fromType", CLASSIFY_TYPE) == CLASSIFY_TYPE) {
                storeGoodsListApi.setCategoryId(getIntent().getIntExtra("categoryId", 0) + "");
            } else {
                storeGoodsListApi.setGoodsName(getIntent().getStringExtra("searchStr"));
            }
//    wangyang 2017-12-20 新增 参数字段labels
            storeGoodsListApi.setLabels(getIntent().getStringExtra("labels"));

            if (goodsBrandId != 0) {
                storeGoodsListApi.setGoodsBrandId(goodsBrandId + "");
            }
            storeGoodsListApi.setQueryField(queryField);
            HttpManager manager = HttpManager.getInstance();
            manager.doHttpDeal(storeGoodsListApi);
        }

    }


    @Override
    public void onRefresh() {
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                //刷新
                goodsListAdapter.clear();
                page = 1;
                getDataList();
            }
        }, 0);
    }

    @Override
    public void onLoadMore() {
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                //刷新
                if (!PhoneUtils.isNetworkConnected(GoodsListActivity.this)) {
                    goodsListAdapter.pauseMore();
                    rvGoodsList.showError();
                    return;
                }
                page++;
                getDataList();

            }
        }, 0);
    }


}
